define(["jquery","bbcare",
        "scprit/followup/app/datatable/datatable.servers.js",
        "scprit/followup/app/datatable/datatable.ui.js"],
    function($,$bb,$datatableServers,$datatableUi){
        var servers = {};
        var URL = $bb.baseUrl("department")+"followup/service";
        /**
         * 入参
         */
        var inParams = function(args){
            var data = JSON.stringify({
                data: {
                    "args": JSON.stringify(args),
                    "deviceId": $.trim($("#deviceId").val()),
                    "phoneNo": $.trim($('#phone').val()),
                    "userName": $.trim($('#userName').val())
                }
            });
            return data;
        }
        /**
         * 出参
         */
        var outParams = function(data){
            return data.rows;
        };
        /**
         * columns
         */
         //设备id
        var deviceId = function(e){
            return e.deviceId ? e.deviceId : "-";
        };
        var deviceType = function(e){
            return e.type == "1" ? "血糖仪" : e.type == "2" ? "手环" : "-";
        };
        var userName = function(e){
            return e.userName ? e.userName : "-";
        };
        var phoneNo = function(e){
            return e.phoneNo ? e.phoneNo : "-";
        };
        //授权状态：
        var status = function(e){
            return e.status == "1" ? '<span class="status">已发放</span>' : "<span>未发放</span>";
        };
        var columnsData = function(){
            var columnsArr = [deviceId,deviceType,userName,phoneNo,status];
            return $datatableServers.getColumnsData(columnsArr);
        };
        /*
        * 初始化后的回调函数：
        * */
        var initComplete = function(){
            $("#phone,#userName,#deviceId").on("input propertychange",function(){
                $datatableUi.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            });
        };
        /**
         * 获取datatable里的options
         */
        servers.getOptions = function(){
            var sessionId = $bb.getSessionStorage("sessionId");
            var options = {
                "ajax": {
                    "url": URL + "/nutrition/device/query?sessionId=" + sessionId,
                    "data": inParams,
                    "dataSrc": outParams
                },
                "columns": columnsData(),
                "initComplete": initComplete
            };
            return options;
        };
        return servers;
    });